<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>更改密码</title>
<!-- 引入jQuery.js文件 -->
<script type="text/javascript" src="static/jquery-easyui-1.4.1/jquery.js"></script>
<!-- 引入easyui小图标文件  -->
<link rel="stylesheet" href="static/jquery-easyui-1.4.1/themes/icon.css">
<link rel="stylesheet" href="static/bootstrapJS/bootstrap.css">
<script type="text/javascript"src="static/bootstrapJS/bootstrap.js"></script>
</head>
<body>
	<div style="width:400px;margin:170px 460px;">
		<form action="" method="post">
			<div class="input-group ">
				<span class="input-group-addon">原密码</span>
				<input type="password" class="form-control" id="pwd" onchange="fun(this.value);" placeholder="原密码">
			</div>
			<div>
				<label id="pwd-error" class="error col-lg-offset-2" for="pwd"></label>
			</div>
			<div class="input-group">
				<span class="input-group-addon">新密码</span>
				<input type="password" class="form-control" id="pwd1" placeholder="新密码">
			</div>
			<div>
				<label id="pwd1-error" class="error col-lg-offset-2" for="pwd1"></label>
			</div>
			<div class="input-group">
				<span class="input-group-addon">新密码</span>
				<input type="password"class="form-control" id="pwd2" placeholder="确认密码">
			</div>
			<div>
				<label id="pwd2-error" class="error col-lg-offset-2" for="pwd2"></label>
			</div>
				<button type="button" id="btn1" class="btn btn-success"style="width:60px;margin-left: 276px;">确定</button>
				<button type="reset"  class="btn btn-primary"style="width:60px;">重置</button>
		</form>
	</div>
	
	<script type="text/javascript">
		function fun(str){
			$.post('pwd', {password: str}, function(data){
				if(!data){
					$("#pwd-error").html("<span style='color:#FF3030;'>原密码输入错误</span>");
				}else {
					$("#pwd-error").html("");
				}
			});
		}
		
		$("#btn1").click(function() {
			var pwd1 = $("#pwd1").val();
			var pwd2 = $("#pwd2").val();
			var str = $("#pwd").val();
			var f = false;
			if (str == "" || str == null) {
				f = true;
				$("#pwd-error").html("<span style='color:#FF3030;'>请输入原密码</span>");
			} else if (pwd1 == "" || pwd1 == null) {
				f = true;
				$("#pwd1-error").html("<span style='color:#FF3030;'>请输入密码</span>");
			} else if (pwd2 == "" || pwd2 == null) {
				f = true;
				$("#pwd1-error").html("");
				$("#pwd2-error").html("<span style='color:#FF3030;'>请确认密码</span>");
			} else if (pwd1 != pwd2) {
				f = true;
				$("#pwd1-error").html("");
				$("#pwd2-error").html("<span style='color:#FF3030;'>两次密码不一致</span>");
			}
	
			if (!f) {
				$.post('pwd', {
					password : str
				}, function(data) {
					if (data) {
						alert("密码修改成功!请重新登陆!");
						window.parent.location = "pwd2?pwd=" + pwd1;
					}
				});
			}
		});
</script>
</body>
</html>